package com.zline.foodraise.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.view.ViewGroup;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.zline.foodraise.R;
import com.zline.foodraise.entity.CommentBean;
import com.zline.foodraise.entity.JsResourceBean;
import com.zline.foodraise.util.ImageUtil;
import com.zline.foodraise.util.LUtil;
import com.zline.foodraise.view.CommentListItem;
import com.zline.foodraise.view.CommentListItem_;
import com.zline.foodraise.view.HotCommentListView;
import com.zline.foodraise.view.HotCommentListView_;
import com.zline.foodraise.view.RecyclerViewLoadMore_;

import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.RootContext;

/**
 * Created by heshantao on 15/8/1.
 * 评论列表Item
 */
@EBean
public class CommentListAdapter extends HeaderBottomBaseRecyclerAdapter<CommentBean, CommentListItem> {
    private static final String LOG_TAG = CommentListAdapter.class.getSimpleName();
    @RootContext
    Context cxt;
    SparseArray<CommentBean> headerArray;
    int resourceType;
    @Bean
    ImageUtil imageUtil;
    DisplayImageOptions options;

    public void setHeaderData(SparseArray<CommentBean> array) {
        this.headerArray=array;
    }

    public void setResourceType(int type){
        this.resourceType=type;
    }

    @Override
    protected HeaderWrapper onCreateHeaderView(ViewGroup parent, int viewType) {
        return new HeaderWrapper(HotCommentListView_.build(cxt));
    }

    @Override
    protected CommentListItem onCreateItemView(ViewGroup parent, int viewType) {
        return CommentListItem_.build(cxt);
    }

    @Override
    protected BottomWrapper onCreateBottomView(ViewGroup parent, int viewType) {
        return new BottomWrapper(RecyclerViewLoadMore_.build(cxt));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof ContentWrapper) {
            CommentListItem view = (CommentListItem) ((ContentWrapper) holder).getView();
            CommentBean commentBean = arrys.get(position - 1);
            view.setRecyclerItemClick(itemClicked);
            if(options==null){
                options = imageUtil.
                        getDisplayImageOptions(R.mipmap.default_person_icon,
                                R.mipmap.default_person_icon, R.mipmap.default_person_icon);
            }
            view.bind(commentBean, position, flag,options);
        } else if (holder instanceof HeaderWrapper) {
            HotCommentListView header = (HotCommentListView) ((HeaderWrapper) holder).getView();
            header.bindHeaderData(headerArray, resourceType,itemClicked);

        }

    }
}
